/**********************************************************************
 * Copyright (c) 2014 Pieter Wuille                                   *
 * Distributed under the MIT software license, see the accompanying   *
 * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
 **********************************************************************/


#ifndef _SECP256K1_HASH_
#define _SECP256K1_HASH_

#include <string.h>
#include "ql_type.h"

// -----------------------
// sha256 definition
// -----------------------
typedef struct {
    OhUint32Type   s[32];
    OhUint32Type buf[16]; /* In big endian */
    OhSizeType   bytes;
} ql_sha256_t;

OhVoidType sha256_init (ql_sha256_t* hash);
OhVoidType sha256_write(ql_sha256_t* hash, const OhByteType* data, OhSizeType len);
OhVoidType sha256_final(ql_sha256_t* hash, OhByteType* out32);

// -----------------------
// hmac definition
// -----------------------
typedef struct {
    ql_sha256_t inner, outer;
} ql_hmac_t;

OhVoidType hmac_init (ql_hmac_t* hash, const OhByteType* key , OhSizeType keylen);
OhVoidType hmac_write(ql_hmac_t* hash, const OhByteType* data, OhSizeType size);
OhVoidType hmac_final(ql_hmac_t* hash, OhByteType* out32);

// -----------------------
// rfc6979 definition
// -----------------------
typedef struct {
    OhByteType v[32];
    OhByteType k[32];
    OhSizeType retry;
} ql_rfc6979_t;

OhVoidType rfc6979_init (ql_rfc6979_t* rng, const OhByteType* key, OhSizeType keylen);
OhVoidType rfc6979_gen  (ql_rfc6979_t* rng, OhByteType* out, OhSizeType outlen);
OhVoidType rfc6979_final(ql_rfc6979_t* rng);
OhVoidType rfc6979_nonce(OhByteType* nonce32, const OhByteType* msg32, const OhByteType* key32, const OhByteType* algo16, OhVoidType *data, OhSizeType counter);

#endif
